import {getExpressCompany} from '@/api/other';

/**
 * 获取物流公司
 * */
const order = {
  state: {
    expressloaded:false, //是否已经获取过
    expresslist:[],
  },
  mutations: {
    SET_EXPRESSLIST: (state, list) => {
      state.expressloaded = true;
      state.expresslist = list;
    },
  },
  actions: { //force:强制刷新
    getExpressList: ({commit,state},force) => {
      return new Promise(resolve => {
        if(!force && state.expressloaded) //不强刷且已经获取过了
        {
          resolve();
        }
        else
        {
          getExpressCompany().then(resp=>{
            commit('SET_EXPRESSLIST',resp.data || []);
            resolve();
          });
        }
        
      });
    },
  },
  getters:{
    expressloaded: state => state.expressloaded,
    expresslist: state => state.expresslist,
  }
};

export default order;

